package com.oe.web;

import com.oe.dao.ResumeDao;
import com.oe.pojo.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Optional;

@Controller
public class ResumeController {

    @Autowired
    ResumeDao resumeDao;

    @RequestMapping("/resume/index")
    public String index(){

        return "resumePage";
    }


    @RequestMapping("/resume/page")
    @ResponseBody
    public List<Resume> page(){
        List<Resume> all = resumeDao.findAll();
        return all;
    }

    @RequestMapping("/resume/delete")
    @ResponseBody
    public String delete(Long id){
        resumeDao.deleteById(id);
      return "true";
    }

    @RequestMapping("/resume/insertOrupdate")
    @ResponseBody
    public String update(Resume resume){
        resumeDao.save(resume);
        return "true";
    }

    @RequestMapping("/resume/queryOne")
    @ResponseBody
    public Resume queryOne(Long id){
        Optional<Resume> byId = resumeDao.findById(id);
        return byId.get();
    }
}
